package com.lovo.bbs.bo;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import javax.naming.NamingException;

import com.lovo.bbs.dao.BoardDao;
import com.lovo.bbs.po.BoardPo;
import com.lovo.bbs.vo.BoardVo;

/**
 * 板块Bo
 * @author tiancen2001
 */
public class BoardBo {
	 //操作类型
	 public static final int OPER_OF_INSERT=1;
	 public static final int OPER_OF_UPDATE=2;
	 public static final int OPER_OF_DELETE=3;
	 
	/**
	 * 返回所有板块Vo列表
	 * @return
	 * @throws SQLException 
	 * @throws NamingException 
	 */
	 public   ArrayList<BoardVo> getAllBoard() {
		 ArrayList<BoardPo> BoardPos=null;
		try {
			BoardPos = new BoardDao().getAllBoard();
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		 ArrayList<BoardVo> boardVos = new ArrayList<BoardVo>();
		 Iterator<BoardPo> itPo = BoardPos.iterator();
		 while(itPo.hasNext()){
			 BoardPo tempPo = itPo.next();
			 BoardVo tempVo = new BoardVo();
			 tempVo.setBoardID(tempPo.getBoardID());
			 tempVo.setBoardName(tempPo.getBoardName());
			 boardVos.add(tempVo);
		 }
    	 return boardVos;
     }
	 
	 /**
	  * 板块更新
	  */
	 public  int updateBoard(BoardVo vo,int operType){
		 int changed=0;
		 BoardPo po = new BoardPo();
		 po.setBoardID(vo.getBoardID());
		 po.setBoardName(vo.getBoardName());
		 try {
			changed = new BoardDao().updateBoard(po,operType);
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		 return changed;
	 }
	 
	 /**
	  * 返回板块Map
	  */
	 public   HashMap<Integer,BoardVo> getBoardMap(ArrayList<BoardVo> vos){
	    HashMap<Integer,BoardVo> boardMap = new HashMap<Integer,BoardVo>();
		Iterator<BoardVo> it = vos.iterator();
		while(it.hasNext()){
			BoardVo vo = it.next();
			boardMap.put(vo.getBoardID(), vo);
		}
		 return boardMap;
	 }
}
